
#include <stdio.h>
#include <stdlib.h>
#include "../../include/ring_buffer.h"


#define BUFFER_SIZE		3


int main(int argc, char *argv[])
{
	char data[2] = {0x65, 0x66};
	char ret[2] = {0x00, 0x00};
	
    ring_buffer_t *buffer;
    buffer = (ring_buffer_t *)malloc(sizeof(ring_buffer_t));

    ring_buffer_init(buffer, BUFFER_SIZE);

    fprintf(stdout, "starts, end = %d, %d\n", ring_buffer_starts_at(buffer), ring_buffer_ends_at(buffer));

    fprintf(stdout, "available data, space = %d, %d\n", 
    				ring_buffer_available_data(buffer), 
    				ring_buffer_available_space(buffer));

    ring_buffer_write(buffer, data, 2);
    fprintf(stdout, "starts, end = %d, %d\n", ring_buffer_starts_at(buffer), ring_buffer_ends_at(buffer));

    fprintf(stdout, "available data, space = %d, %d\n", 
    				ring_buffer_available_data(buffer), 
    				ring_buffer_available_space(buffer));


    ring_buffer_write(buffer, data, 2);
    fprintf(stdout, "starts, end = %d, %d\n", ring_buffer_starts_at(buffer), ring_buffer_ends_at(buffer));

    fprintf(stdout, "available data, space = %d, %d\n", 
    				ring_buffer_available_data(buffer), 
    				ring_buffer_available_space(buffer));

    ring_buffer_read(buffer, ret, 1);
    fprintf(stdout, "read value is %d\n", ret[0]);
    
    fprintf(stdout, "starts, end = %d, %d\n", ring_buffer_starts_at(buffer), ring_buffer_ends_at(buffer));

    fprintf(stdout, "available data, space = %d, %d\n", 
    				ring_buffer_available_data(buffer), 
    				ring_buffer_available_space(buffer));



    ring_buffer_read(buffer, ret, 1);
    fprintf(stdout, "read value is %d\n", ret[0]);
    
    fprintf(stdout, "starts, end = %d, %d\n", ring_buffer_starts_at(buffer), ring_buffer_ends_at(buffer));

    fprintf(stdout, "available data, space = %d, %d\n", 
    				ring_buffer_available_data(buffer), 
    				ring_buffer_available_space(buffer));


	ring_buffer_read(buffer, ret, 1);
    fprintf(stdout, "read value is %d\n", ret[0]);
    
    fprintf(stdout, "starts, end = %d, %d\n", ring_buffer_starts_at(buffer), ring_buffer_ends_at(buffer));

    fprintf(stdout, "available data, space = %d, %d\n", 
    				ring_buffer_available_data(buffer), 
    				ring_buffer_available_space(buffer));


    
    return 0;
}
